package com.example.weixinsystem.controller;

import com.example.weixincommonlog.annotation.WxLog;
import com.example.weixincommonlog.enums.BusinessType;
import com.example.weixinsystem.service.SysRoleService;
import com.weixin.common.core.domain.Result;
import com.weixin.common.core.form.LoginUserDetails;
import com.weixin.common.core.form.RoleAddForm;
import com.weixin.common.core.utils.SecurityUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色控制器
 *
 * @version 1.0.0
 * @className: RoleController
 * @description: 角色控制器
 * @author: zhangjunfa
 * @date: 2023/5/29 15:45
 */
@Slf4j
@RestController
@RequestMapping("role")
public class RoleController {

    private final SysRoleService sysRoleService;

    public RoleController(SysRoleService sysRoleService) {
        this.sysRoleService = sysRoleService;
    }

    /**
     * 新增角色
     *
     * @param addForm 新增参数
     * @return 成功
     */
    @PostMapping("/add")
    @PreAuthorize("@ss.hasPermi('system:role:add')")
    @WxLog(title = "新增角色",type = BusinessType.ADD)
    public Result<?> addRole(@Validated RoleAddForm addForm) {
        this.sysRoleService.addRole(addForm);
        return Result.ok();
    }

    /**
     * 获取角色集合
     *
     * @return 角色集合
     */
    @GetMapping("/getRoleList")
    @PreAuthorize("@ss.hasPermi('system:role:query')")
    public Result<?> getRoleList() {
        LoginUserDetails loginUser = SecurityUtil.getLoginUser();
        return Result.ok(loginUser);
    }


}
